package com.xinpu.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xinpu.entity.TSalesOrder;
import com.xinpu.entity.TUser;
import com.xinpu.service.*;
import com.xinpu.vo.ResponseMessage;
import com.xinpu.vo.SalesOrederVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/salesOrder")
@Api(tags = "销售订单表")
public class SalesOrderController {

    @Autowired
    private SalesOrderService salesOrderService;
    @Autowired
    private ITCompanyService itCompanyService;

    /**
     * 订单列表
     *
     * @param page
     * @param size
     * @param userName
     * @param salesName
     * @param start
     * @param over
     * @param orderId
     * @return
     */
    @GetMapping("/list")
    public ResponseMessage list(
            @RequestParam("page") Integer page,
            @RequestParam("size") Integer size,
            @RequestParam(value = "userName", required = false) String userName,
            @RequestParam(value = "salesName", required = false) String salesName,
            @RequestParam(value = "start", required = false) String start,
            @RequestParam(value = "over", required = false) String over,
            @RequestParam(value = "orderId", required = false) String orderId
    ) {
        String tenantId = OwnService.getLoginer().getTenantId();
        return ResponseMessage.ok(salesOrderService.list(salesName, userName, orderId, start, over, page, size, tenantId));

    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public ResponseMessage findById(@RequestParam("id") Integer id) {
        return ResponseMessage.ok(salesOrderService.findById(id));
    }

    /**
     * 合同列表
     *
     * @param page
     * @param size
     * @param name
     * @return
     */
    @GetMapping("/contract")
    public ResponseMessage contract(@RequestParam("page") Integer page,
                                    @RequestParam("size") Integer size,
                                    @RequestParam(value = "name", required = false) String name) {
        return ResponseMessage.ok(salesOrderService.contract(page, size, name));
    }

}
